package com.may.demo.controller;

import com.may.demo.core.R;
import com.may.demo.pojo.Order;
import com.may.demo.service.OrderService;
import com.may.demo.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: demo
 * @description:
 * @author: Bobby.Ma
 * @create: 2020-09-19 19:53
 **/
@Slf4j
@RestController
public class OrderController {

    @Autowired
    private OrderService orderService;

    @Autowired
    private UserService userService;

    @GetMapping("/list")
    public R getOrderList() {
        return R.success(orderService.getOrderList());
    }

    @GetMapping("/{id}")
    public R getOrder(@PathVariable Integer id){
        return R.success(orderService.getOrder(id));
    }

    @PostMapping("/save")
    public R saveOrder(@RequestBody Order order) {
        return R.success(orderService.saveOrder(order));
    }

    @PutMapping("/update")
    public R updateOrder(@RequestBody Order order) {
        return R.success(orderService.updateOrder(order));
    }

    @DeleteMapping("/{id}")
    public R deleteOrder(@PathVariable Integer id) {
        return R.success(orderService.deleteOrder(id));
    }

    @GetMapping("/d2")
    public R dependency2(){
        List<Order> list = orderService.getOrderList();
        log.info("订单：{}",list);
        String say = userService.say("nhb");
        return R.success(say);
    }
}
